<?php
include_once ("video.php");
include_once ("mysqllib.php");
include_once ("globals.php");
class videoList {
	private $listVideos = array();

	public function __construct() {
		$this -> getAllVideosForUser();
	}

	public function getAllVideosForUser() {
		session_start();
		$db = new mysqllib();
		$queryCourse = "SELECT * FROM IsRegistered WHERE idUser=" . $_SESSION['idUser'];
		$resultCourse = mysql_query($queryCourse);

		while ($dataCourse = mysql_fetch_array($resultCourse)) {
			$idCourse = $dataCourse['idCourse'];
			$queryVideo = "SELECT * FROM Video WHERE idCourse=$idCourse";
			$resultVideo = mysql_query($queryVideo);

			while ($dataVideo = mysql_fetch_array($resultVideo)) {
				$video = new video();
				$video -> setVideo($dataVideo['idVideo'], $dataVideo['titleVideo'], $dataVideo['pathVideo'], $dataVideo['nameVideo'], $dataVideo['postingDate']);
				array_push($this -> listVideos, $video);
			}
		}
	}

	public function displayAllVideosForUser() {
		session_start();
		echo '<table id="listVideos">';
		echo '<tr><th>Videos Available</th>';
		if ($_SESSION['status'] == $GLOBALS['admin']) {
			echo '<th><button onclick="location.href=\'index.php?page=adminPage\'">Admin Page</button></th>';
		}
		echo '</tr>';
		foreach ($this->listVideos as $vid) {
			echo '<tr> <td>';
			echo '<a href="index.php?page=video&id=' . $vid -> getIdVideo() . '">' . $vid -> getTitle() . '</a>';
			echo '</td> </tr>';
		}
		echo '</table>';

	}

}
?>
